﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using YArchitech.DataModel;

namespace YArchitech.HVAC.Nozzle
{
	public class NozzleSqlData
	{
		public NozzleSqlData()
		{
			this.GetNozzleSqlData();
		}

		public void GetNozzleSqlData()
		{
			this.dtGlobeNozzle = this.sdf.GetPumpDataTable("GlobleNozzle");
			this.dtGlobeNozzleFormat = this.sdf.GetPumpDataTable("GlobleNozzleFormat");
			this.dtCylindricalNozzle = this.sdf.GetPumpDataTable("CylindricalNozzle");
			this.dtCylindricalNozzleFormat = this.sdf.GetPumpDataTable("CylindricalNozzleFormat");
		}

		public List<GlobeNozzle> GetGlobeNozzle(GlobeFormData gfd)
		{
			List<GlobeNozzle> list = new List<GlobeNozzle>();
			foreach (object obj in this.dtGlobeNozzle.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if ((!(dataRow["SheCheng"].ToString() != gfd.SheCheng.ToString()) || !gfd.IsSheCheng) && (Math.Abs(Convert.ToDouble(dataRow["FengSu"].ToString()) - gfd.FengSu) <= 0.001 || !gfd.IsFengSu) && (!gfd.IsFengLiang || (Convert.ToInt32(dataRow["FengLiang"].ToString()) <= gfd.FengliangM && Convert.ToInt32(dataRow["FengLiang"].ToString()) >= gfd.FengliangL)))
				{
					GlobeNozzle globeNozzle = new GlobeNozzle
					{
						FengSu = Convert.ToDouble(dataRow["FengSu"].ToString()),
						SheCheng = Convert.ToInt32(dataRow["SheCheng"].ToString()),
						FengLiang = Convert.ToInt32(dataRow["FengLiang"].ToString()),
						GuiGe = Convert.ToInt32(dataRow["GuiGe"].ToString())
					};
					DataView dataView = this.dtGlobeNozzleFormat.AsDataView();
					dataView.RowFilter = "GuiGe=" + globeNozzle.GuiGe;
					globeNozzle.FengKouDn = Convert.ToDouble(dataView[0]["FengKouDn"].ToString());
					globeNozzle.HouKouDn = Convert.ToDouble(dataView[0]["HouKouDn"].ToString());
					globeNozzle.D1 = Convert.ToDouble(dataView[0]["D1"].ToString());
					globeNozzle.D2 = Convert.ToDouble(dataView[0]["D2"].ToString());
					globeNozzle.D3 = Convert.ToDouble(dataView[0]["D3"].ToString());
					globeNozzle.D4 = Convert.ToDouble(dataView[0]["D4"].ToString());
					globeNozzle.E = Convert.ToDouble(dataView[0]["E"].ToString());
					globeNozzle.F = Convert.ToDouble(dataView[0]["F"].ToString());
					globeNozzle.L1 = Convert.ToDouble(dataView[0]["L1"].ToString());
					globeNozzle.L2 = Convert.ToDouble(dataView[0]["L2"].ToString());
					list.Add(globeNozzle);
				}
			}
			return list;
		}

		public List<CylindricalNozzle> GetCylindricalNozzle(CylindricalFormData cfd)
		{
			List<CylindricalNozzle> list = new List<CylindricalNozzle>();
			foreach (object obj in this.dtCylindricalNozzle.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				if ((!(dataRow["Count"].ToString() != cfd.Count.ToString()) || cfd.Count == 0) && (!cfd.IsSheCheng || (Convert.ToInt32(dataRow["SheCheng"].ToString()) <= cfd.SheChengM && Convert.ToInt32(dataRow["SheCheng"].ToString()) >= cfd.SheChengL)) && (!cfd.IsQiLiu || (Convert.ToDouble(dataRow["QiLiu"].ToString()) <= cfd.QiLiuM && Convert.ToDouble(dataRow["QiLiu"].ToString()) >= cfd.QiLiuL)) && (!cfd.IsFengLiang || (Convert.ToInt32(dataRow["FengLiang"].ToString()) <= cfd.FengliangM && Convert.ToInt32(dataRow["FengLiang"].ToString()) >= cfd.FengliangL)))
				{
					CylindricalNozzle cylindricalNozzle = new CylindricalNozzle
					{
						Count = Convert.ToInt32(dataRow["Count"].ToString()),
						QiLiu = Convert.ToDouble(dataRow["QiLiu"].ToString()),
						SheCheng = Convert.ToInt32(dataRow["SheCheng"].ToString()),
						FengLiang = Convert.ToInt32(dataRow["FengLiang"].ToString()),
						GuiGe = Convert.ToInt32(dataRow["GuiGe"].ToString())
					};
					DataView dataView = this.dtCylindricalNozzleFormat.AsDataView();
					dataView.RowFilter = "GuiGe=" + cylindricalNozzle.GuiGe;
					cylindricalNozzle.FengKouDn = Convert.ToDouble(dataView[0]["FengKouDn"].ToString());
					cylindricalNozzle.HouKouDn = Convert.ToDouble(dataView[0]["HouKouDn"].ToString());
					cylindricalNozzle.C = Convert.ToDouble(dataView[0]["C"].ToString());
					cylindricalNozzle.L2 = Convert.ToDouble(dataView[0]["L2"].ToString());
					cylindricalNozzle.L3 = Convert.ToDouble(dataView[0]["L3"].ToString());
					cylindricalNozzle.L = Convert.ToDouble(dataView[0]["L"].ToString());
					cylindricalNozzle.D = Convert.ToDouble(dataView[0]["D"].ToString());
					cylindricalNozzle.E = Convert.ToDouble(dataView[0]["E"].ToString());
					cylindricalNozzle.F = Convert.ToDouble(dataView[0]["F"].ToString());
					cylindricalNozzle.B = Convert.ToDouble(dataView[0]["B"].ToString());
					cylindricalNozzle.H = Convert.ToDouble(dataView[0]["H"].ToString());
					list.Add(cylindricalNozzle);
				}
			}
			return list;
		}

		public void BindDataGridDataGlobe(DataGridView dataGridView, GlobeFormData gfd)
		{
			dataGridView.Rows.Clear();
			List<GlobeNozzle> globeNozzle = this.GetGlobeNozzle(gfd);
			if (globeNozzle.Count < 1)
			{
				return;
			}
			foreach (GlobeNozzle globeNozzle2 in globeNozzle)
			{
				dataGridView.Rows.Add(new object[]
				{
					globeNozzle2,
					globeNozzle2.FengSu,
					globeNozzle2.SheCheng,
					globeNozzle2.FengLiang,
					globeNozzle2.GuiGe,
					globeNozzle2.FengKouDn,
					globeNozzle2.HouKouDn
				});
			}
		}

		public void BindDataGridDataCy(DataGridView dataGridView, CylindricalFormData cfd)
		{
			dataGridView.Rows.Clear();
			List<CylindricalNozzle> cylindricalNozzle = this.GetCylindricalNozzle(cfd);
			if (cylindricalNozzle.Count < 1)
			{
				return;
			}
			foreach (CylindricalNozzle cylindricalNozzle2 in cylindricalNozzle)
			{
				dataGridView.Rows.Add(new object[]
				{
					cylindricalNozzle2,
					cylindricalNozzle2.QiLiu,
					cylindricalNozzle2.SheCheng,
					cylindricalNozzle2.FengLiang,
					cylindricalNozzle2.GuiGe,
					cylindricalNozzle2.FengKouDn,
					cylindricalNozzle2.HouKouDn
				});
			}
		}

		private HYMEPDatasourceReader sdf = new HYMEPDatasourceReader();

		private DataTable dtGlobeNozzle;

		public DataTable dtGlobeNozzleFormat;

		public DataTable dtCylindricalNozzle;

		public DataTable dtCylindricalNozzleFormat;
	}
}
